package com.example.jl.bethinner.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.jl.bethinner.R;
import com.example.jl.bethinner.domain.Province;
import com.example.jl.bethinner.util.ViewHolder;

import java.util.List;

/**
 * Created by JL on 8/7/15.
 */
public class HELProvinceChooserAdapter extends BaseAdapter {
    private Context context;
    private List<Province> provinces;
    private int selectPos;

    public HELProvinceChooserAdapter(Context context, List<Province> provinces) {
        this.context = context;
        this.provinces = provinces;
    }

    public void setPositionId(int id) {
        this.selectPos = id;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return provinces.size();
    }

    @Override
    public String getItem(int position) {
        return provinces.get(position).getProvinceid();
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = LayoutInflater.from(context).inflate(R.layout.itme_city_chooser, parent, false);
        TextView province_name = ViewHolder.get(convertView, R.id.city);
        province_name.setText(provinces.get(position).getProvince());
        if (selectPos == position) {
            province_name.setBackgroundResource(R.color.bottom_add_modules_btn_press_background_color);
        } else {
            province_name.setBackgroundResource(R.color.white);
        }
        return convertView;
    }
}
